import numpy as np

# 1. 数据生成：模拟棋盘上的点集
np.random.seed(42)
num_points = 10    # 棋盘上的点数
dimensions = 2    # 棋盘为二维
# 生成随机点集，表示棋盘上的位置
point_set = np.random.randint(0, 8, (num_points, dimensions))  # 假设棋盘为8x8
# 模拟一个目标点
target_point = np.random.randint(0, 8, (1, dimensions))

# 2. 切比雪夫距离计算函数
def chebyshev_distance(point1, point2):
    """ 
    计算两个点之间的切比雪夫距离
    """ 
    return np.max(np.abs(point1 - point2))

# 3. 逐点计算与目标点的切比雪夫距离
distances = []
for p in point_set:
    distance = chebyshev_distance(p, target_point)
    distances.append(distance)

# 4. 批量计算切比雪夫距离
distances_np = np.max(np.abs(point_set - target_point), axis=1)

# 5. 输出结果
print("棋盘上的点集（随机生成）:")
print(point_set)
print("\n目标点:")
print(target_point[0])
print("\n逐点计算的切比雪夫距离:")
for i, d in enumerate(distances):
    print(f"点{i + 1}: 距离={d}")

print("\nNumPy批量计算的切比雪夫距离:")
print(distances_np)